package org.qianji.goosql.dql.clause;

import java.util.List;
import java.util.Map;

import org.qianji.goosql.table.Table;

/**
 * 简单From子句，用于表示直接查询某个表。
 * 
 * @author gmz
 * 
 */
public class SimpleFrom extends AbstractFrom {

	/**
	 * 
	 */
	private static final long serialVersionUID = -950201131753619345L;

	private Table table;

	/**
	 * 根据表构造简单From子句。
	 * 
	 * @param table
	 *            {@link Table} 表
	 */
	public SimpleFrom(Table table) {
		super();
		if (table == null) {
			throw new NullPointerException("table can't be null");
		}
		this.table = table;
	}

	/**
	 * 获取表。
	 * 
	 * @return {@link Table} 表
	 */
	public Table getTable() {
		return table;
	}

	@Override
	public String toSql() {
		StringBuffer frm = new StringBuffer("FROM ").append(table.toSql());
		return frm.toString();
	}

	@Override
	public List<Object> getPlacedParameters() {
		return table.getPlacedParameters();
	}

	@Override
	public Map<String, Object> getNamedParameters() {
		return table.getNamedParameters();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null || !(obj instanceof SimpleFrom)) {
			return false;
		}
		if (table.equals(((SimpleFrom) obj).getTable())) {
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		int hc = 37 * 17 + table.hashCode();
		return hc;
	}

	@Override
	public String toString() {
		return toSql();
	}

}
